<?php
	function completion($msg,$num){//补0
		$n=pow(10,$num);
		$n=$n+$msg;
		$n=substr($n,1,$num);
		return $n;
	}
	function upimages($name,$address,$image){//上传图片
		header("content-type:text/html;charset=utf-8");//上传图片并改变大小
        date_default_timezone_set("PRC");
        $pImg=$_FILES["$image"];
        if(isset($pImg)){
            if($pImg['error']==UPLOAD_ERR_OK){
            //取得扩展名
            $extName=strtolower(end(explode('.',$pImg['name'])));
            //echo $extName;
            $filename_picture=$name.".".$extName;
            //echo $filename;
            $dest_picture="Public/".$address."/".$filename_picture;//
            move_uploaded_file($pImg['tmp_name'],$dest_picture);
		    return $dest_picture;//地址
	        }
	    }
	}
	function int_number($msg){//多0.2取整
		$n=$msg%100;
		$m=floor($msg/100);
		if($n>20){
			$m=$m+1;
		}
		return $m;
	}
	function snocompletion($sno){
		if(strlen($sno)<12){
		    $sno=100000000000+$sno;
		}
		return $sno;
	}
	function ant($ant){
		$ant=preg_replace('#,{2,}#',',',$ant);
		$ant=ltrim($ant,',');
		$ant=rtrim($ant,',');
		return $ant;
	}
	function i_array_column($input, $columnKey, $indexKey=null){//array_column二维转一维
		if(!function_exists('array_column')){ 
			$columnKeyIsNumber  = (is_numeric($columnKey))?true:false; 
			$indexKeyIsNull            = (is_null($indexKey))?true :false; 
			$indexKeyIsNumber     = (is_numeric($indexKey))?true:false; 
			$result                         = array(); 
			foreach((array)$input as $key=>$row){ 
				if($columnKeyIsNumber){ 
					$tmp= array_slice($row, $columnKey, 1); 
					$tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null; 
				}else{ 
					$tmp= isset($row[$columnKey])?$row[$columnKey]:null; 
				} 
				if(!$indexKeyIsNull){ 
					if($indexKeyIsNumber){ 
					  $key = array_slice($row, $indexKey, 1); 
					  $key = (is_array($key) && !empty($key))?current($key):null; 
					  $key = is_null($key)?0:$key; 
					}else{ 
					  $key = isset($row[$indexKey])?$row[$indexKey]:0; 
					} 
				} 
				$result[$key] = $tmp; 
			} 
			return $result; 
		}else{
			return array_column($input, $columnKey, $indexKey);
		}
    }
	function https_request($url,$data = null){//curl
		$curl = curl_init();  
        curl_setopt($curl,CURLOPT_URL,$url);  
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);  
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);  
        if(!empty($data)){//post
            curl_setopt($curl,CURLOPT_POST,1);  
            curl_setopt($curl,CURLOPT_POSTFIELDS,$data);  
        }  
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);  
        $output = curl_exec($curl);  
        curl_close($curl);  
        return $output;
	}
	function dateMonths($start_date,$end_date,$explode='-',$addOne=false){
		$start_int = strtotime($start_date);
		$end_int = strtotime($end_date);
		if($start_int>$end_int){
			$tmp=$start_date;
			$start_date=$end_date;
			$end_date=$tmp;
		}
		$start_arr = explode($explode,$start_date);
		$start_year = intval($start_arr[0]);
		$start_month = intval($start_arr[1]);
		$start_day = intval($start_arr[2]);
		$end_arr = explode($explode,$end_date);
		$end_year = intval($end_arr[0]);
		$end_month = intval($end_arr[1]);
		$end_day = intval($end_arr[2]);
		$data = array();
		//$data[] = $start_date;
		$tmp_month = $start_month;
		$tmp_year = $start_year;
		while (!(($tmp_month > $end_month) && ($tmp_year == $end_year))) {
			if($tmp_month > 12){
				$tmp_month = 1;
				$tmp_year++;
			}
			$data[] = $tmp_year.$explode.str_pad($tmp_month,2,'0',STR_PAD_LEFT);
			$tmp_month++;
		}
		if($addOne == true){
			$tmp_month ++;
			//超过十二月份，到新年的一月份
			if($tmp_month > 12){
				$tmp_month = 1;
				$tmp_year++;
			}
			$data[] = $tmp_year.$explode.str_pad($tmp_month,2,'0',STR_PAD_LEFT);
		}
		if($start_day>$end_day){
			array_pop($data);
		}
		return $data;
	}
	function getDateFromRange($startdate, $enddate){
		$stimestamp = strtotime($startdate);
		$etimestamp = strtotime($enddate);

		// 计算日期段内有多少天
		$days = ($etimestamp-$stimestamp)/86400+1;

		// 保存每天日期
		$date = array();

		for($i=0; $i<$days; $i++){
			$date[] = date('Y-m-d', $stimestamp+(86400*$i));
		}

		return $date;
	}
	function getMonth($sign){  
		//得到系统的年月  
		$tmp_date=date("Ym");  
		//切割出年份  
		$tmp_year=substr($tmp_date,0,4);  
		//切割出月份  
		$tmp_mon =substr($tmp_date,4,2);  
		// 得到当前月份的下几月
		$tmp_nextmonth=mktime(0,0,0,$tmp_mon+$sign,1,$tmp_year);  
		// 得到当前月份的前几月
		$tmp_forwardmonth=mktime(0,0,0,$tmp_mon-$sign,1,$tmp_year);  
		return $fm_next_month=date("Y-m",$tmp_forwardmonth);          
    }
	function checkdays($year,$month){
		if (in_array($month, array(1,3,5,7,8,10,12))) {
			return '31';
		   }elseif ($month == 2){
			if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) {        //判断平年、闰年二月份的天数
				return '29';
		  }else{
				return '28';
		  }
		} else {
			return '30';
	   }
	}
?>